package com.example.commtribute;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class ReportsActivity extends Activity {

	private ArrayList<Report> reports;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reports);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
        reports = new ArrayList<Report>();
        reports.add(new Report("Pothole on University Avenue","description",new Date("01/01/01"),10));
        reports.add(new Report("Theatre needs re-painted","description",new Date("01/01/01"),9));
        reports.add(new Report("Bus shelter vandalised","description",new Date("01/01/01"),8));
        reports.add(new Report("Traffic lights need repaired","description",new Date("01/01/01"),7));
        reports.add(new Report("Broken glass all over swingpark","description",new Date("01/01/01"),7));
        reports.add(new Report("Lamppost damaged by car","description",new Date("01/01/01"),7));
        reports.add(new Report("Traffic lights need repaired","description",new Date("01/01/01"),6));
        reports.add(new Report("School wall needs graffiti removed","description",new Date("01/01/01"),0));
        reports.add(new Report("Traffic lights need repaired","description",new Date("01/01/01"),0));
        reports.add(new Report("Who has a lighter?","description",new Date("01/01/01"),-6));
        reports.add(new Report("Anyone seen my wallet?","description",new Date("01/01/01"),-7));
        reports.add(new Report("Cat stuck up tree","description",new Date("01/01/01"),-8));
        reports.add(new Report("Tony smells","description",new Date("01/01/01"),-17));
        for(Report r: reports)
        {
            TableRow row = new TableRow(this);
            String title = r.getTitle();
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
            String date = df.format(r.getDate());
            int netVotes = r.getNetVotes();
            TextView tvTitle = new TextView(this);
            TextView tvDate = new TextView(this);
            TextView tvNetVotes = new TextView(this);
            tvTitle.setText(""+title);
            tvDate.setText(""+date);
            tvNetVotes.setText(""+netVotes);
            tvTitle.setTextAppearance(getApplicationContext(), R.style.rowTitleText);
            tvDate.setTextAppearance(getApplicationContext(), R.style.rowDateText);
            if (netVotes > 0){
            	tvNetVotes.setTextAppearance(getApplicationContext(), R.style.rowPosVoteText);
            }
            else if (netVotes == 0){
            	tvNetVotes.setTextAppearance(getApplicationContext(), R.style.rowZeroVoteText);
            }
            else{
            	tvNetVotes.setTextAppearance(getApplicationContext(), R.style.rowNegVoteText);
            }
            row.addView(tvTitle);            
            row.addView(tvDate);
            row.addView(tvNetVotes);
            row.setBackgroundDrawable(getResources().getDrawable(R.drawable.rowstyle));
            table.addView(row);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_reports, menu);
        return true;
    }

    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
